package clientUtilGUI;

import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JToolBar;

import clientMain.Login;
import clientMain.Main;
import clientView.Employee_Add;
import clientView.Employee_ConditionList;
import clientView.Employee_Search;

public class Tab_Employee extends JToolBar implements ActionListener {

	private JButton btnEmSearch, btnEmAdd;
	private JButton btnEmList;
	
	public Tab_Employee(){
		setFloatable(false);
		setOrientation(JToolBar.HORIZONTAL);
		setMargin(new Insets(0, 6, 0, 2));
				
		btnEmSearch = new JButton(UtilityGUI.subMenuEmSearch, new ImageIcon("src/image/user_executive_red_01.png"));
		btnEmSearch.setVerticalTextPosition(JButton.BOTTOM);
		btnEmSearch.setHorizontalTextPosition(JButton.CENTER);
		btnEmSearch.addActionListener(this);
		add(btnEmSearch);
		
		for(int i = 0; i<Login.listAuthorization.size(); i++){
			if(Login.listAuthorization.get(i).getModuleName().equals("Employee") &&
					Login.listAuthorization.get(i).getPermName().equals("Add")){
				btnEmAdd = new JButton(UtilityGUI.subMenuEmAdd, new ImageIcon("src/image/PersonAdd.png"));
				btnEmAdd.setVerticalTextPosition(JButton.BOTTOM);
				btnEmAdd.setHorizontalTextPosition(JButton.CENTER);
				btnEmAdd.addActionListener(this);
				add(btnEmAdd);
				break;
			}
		}
		
		btnEmList = new JButton(UtilityGUI.subMenuEmList, new ImageIcon("src/image/user_group.png"));
		btnEmList.setVerticalTextPosition(JButton.BOTTOM);
		btnEmList.setHorizontalTextPosition(JButton.CENTER);
		btnEmList.addActionListener(this);
		add(btnEmList);
		
	}
	
	@Override
	public void actionPerformed(ActionEvent e) {
		if(e.getSource() == btnEmAdd){
			int index = Main.jTabbedPane.positionTab(UtilityGUI.tabEmAdd);
			if(index == -1){
				Main.jTabbedPane.addTab(new Employee_Add(), UtilityGUI.tabEmAdd);
				Main.jTabbedPane.setSelectedIndex(Main.jTabbedPane.getTabCount()-1);
			}else{
				Main.jTabbedPane.setSelectedIndex(index);
				return;
			}
		}
		
		if(e.getSource() == btnEmList){
			new Employee_ConditionList(Main.main).setVisible(true);
		}
		
		if(e.getSource() == btnEmSearch){
			int index = Main.jTabbedPane.positionTab(UtilityGUI.tabEmSearch);
			if(index == -1){
				Main.jTabbedPane.addTab(new Employee_Search(), UtilityGUI.tabEmSearch);
				Main.jTabbedPane.setSelectedIndex(Main.jTabbedPane.getTabCount()-1);
			}else{
				Main.jTabbedPane.setSelectedIndex(index);
				return;
			}
		}
		
	}
}
